home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3084 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.3 KB  |  84 lines

  1. Path: boy.nmd.msu.ru!not-for-mail
  2. From: krotoff@such.srcc.msu.su (Alexander Krotoff)
  3. Newsgroups: comp.lang.c++
  4. Subject: a lady need help
  5. Date: 21 Jan 1996 22:24:38 +0300
  6. Organization: Research Computer Center, Moscow State University
  7. Sender: krotoff@boy.nmd.msu.ru
  8. Message-ID: <4du3tm$3cm@boy.nmd.msu.ru>
  9. References: <4drln1$f9i$1@mhadg.production.compuserve.com>
  10. NNTP-Posting-Host: boy.nmd.msu.ru
  11. X-Comment-To: linda siu <103051.3457@CompuServe.COM>
  12.  
  13. linda siu <103051.3457@CompuServe.COM> wrote:
  14. > I lost my job and went for an interview lately.
  15. > I am still confuse about some of the c++ question.
  16. > Please help !
  17. > a)  What is a initialization list and when/how to use it.
  18.  
  19. `initialization list' is not defined in the C++.
  20.  
  21. It probably is `initializer list'. It is construction
  22. like following:
  23.  
  24. struct A {
  25.     int b;
  26.     int c;
  27. };
  28.  
  29. struct A aa[2] = { {1,2}, {3,4} };
  30.         ^^^^^^^^^^^^^^^^^
  31. This list is called initializer list.
  32. It may be used to initialize any aggregate class
  33. (aggregate classes are very similar to C style 
  34. structs and unions) and arrays.
  35.  
  36. Probably it is `ctor initializer list' this is used
  37. in the constructor body to pass parameters to the base
  38. classes constructors and to initialize members of the
  39. class. In C++ initialization and assignments are
  40. distingushed.
  41. For example it is impossible to initialize member
  42. of reference type different way.
  43. Example:
  44.  
  45. class B {
  46.  public:
  47.     int &a;
  48.     B (int &p): a(b) {}
  49.     //          ^^^^
  50. };
  51.  
  52. class D: public B {
  53.  public:
  54.     D (int &p): B(p) {}
  55.     //          ^^^^
  56. };
  57.  
  58. In the first case we use ctor initializer to initialize
  59. class member. In the second case we used it to pass parameter
  60. to base class constructor.
  61.  
  62. > b) what is the advantage of new/delete over malloc/free.
  63.  
  64. There are a number of new faeatures. At first: malloc is
  65. not typed (it returns `void*' it is not siignifant in C,
  66. but significant in c++), but new "returns" typed pointer.
  67. new and delete operators knows about C++ costructors and 
  68. destructors, but malloc do not.
  69.  
  70. If you proogramming on the c++ you shell avoid to use
  71. malloc() and free() at least while you are not expert
  72. in this area ;-)
  73.  
  74. Regards,
  75. --
  76. Alexander N. Krotoff        krotoff@such.srcc.msu.su
  77. Research Computer Center    tel: +7(095)939-2638
  78. Moscow State University        fax: +7(095)939-4430
  79.  
  80. ε╒ ╦┴╦ ┬┘╠╧ ╬┼ ╒┬╠┴╓╔╘╪ ─┴═╧▐╦╒...
  81.